﻿using B.S.Ingredients.APIRead.Application.Command.Imginfors;
using B.S.Ingredients.Domain;
using B.S.Ingredients.ErrorCode;
using B.S.Ingredients.Infartructrue.Interfaces;
using MediatR;

namespace B.S.Ingredients.APIRead.Application.CommandHandler.Imginforsa
{
    public class ImgInforCommandHandler : IRequestHandler<ImgInforCommand, APIResult<int>>
    {
        public ImgInforCommandHandler(IBaseRepository<ImgInfor> imginforRepository)
        {
            ImginforRepository = imginforRepository;
        }

        public IBaseRepository<ImgInfor> ImginforRepository { get; }

        public async Task<APIResult<int>> Handle(ImgInforCommand request, CancellationToken cancellationToken)
        {
            var path = await ImginforRepository.CreateAsync(request.Data);
            return new APIResult<int>
            {
                Code = ResultCode.success,
                Mag = "",
                Data = path
            };
        }
    }
}
